package com.yc.cloud.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.cloud.business.DemoBusiness;
import com.yc.cloud.common.model.response.Outcome;
import com.yc.cloud.demo.entity.Demo;
import com.yc.cloud.model.FindDemoPage;
import com.yc.cloud.model.SaveDemo;
import com.yc.cloud.model.UpdateDemo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 杨智杰
 * @date 2021/8/13 14:07
 */
@Api(tags = "演示相关接口")
@RestController
@RequestMapping
public class DemoApi {

    @Resource
    private DemoBusiness demoBusiness;

    @GetMapping
    @ApiOperation("分页")
    public Outcome<IPage<Demo>> page(FindDemoPage param) {
        return Outcome.success(demoBusiness.page(param));
    }

    @PostMapping
    @ApiOperation("新增")
    public Outcome save(@RequestBody @Valid SaveDemo param) {
        return Outcome.status(demoBusiness.save(param));
    }

    @PutMapping
    @ApiOperation("修改")
    public Outcome update(@RequestBody @Valid UpdateDemo param) {
        return Outcome.status(demoBusiness.update(param));
    }

    @DeleteMapping
    @ApiOperation("删除")
    public Outcome delete(@RequestBody List<Long> id) {
        return Outcome.status(demoBusiness.delete(id));
    }

}
